using System;

namespace Sedna.Core.Common.Objects.Navigation
{
	public class ScopePath: IScopePath
	{
		private string path;
		private NavigationNode topNode;
		
		internal ScopePath(string path, NavigationNode topNode)
		{
			this.path=path;
			this.topNode=topNode;
		}

		public object Value
		{
			get
			{
				try
				{
					object result = topNode.Value;
                    if (result is IValueWrapper)
                    {
                        return ((IValueWrapper)result).GetValue(typeof(object));
                    }
                    return result;
				    
				}
			    catch (NullReferenceException e)
			    {
                    return null;
			    }
				catch (Exception e)
				{
					throw new SednaException(String.Format("Error occured while trying to get value from path \"{0}\". Check path string format.", path), e);
				}
			}
			set 
			{ 
				try
				{
					topNode.Value=value;
				}
				catch (Exception e)
				{
					throw new SednaException(String.Format("Error occured while trying to set value to path \"{0}\". Check path string format.", path), e);
				}
			}
		}
	}
}
